package com.hex.ds.hdrs.common.utils;

import com.hex.bigdata.hbda.security.vo.OnlineUser;
import com.hex.bigdata.hbda.utils.RequestHelper;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.UUID;

/**
 * @Package: com.hex.ds.hdrs.common.utils
 * @ClassName BaseUtil
 * @Description:
 * @Author: 基础工具类<gc.zuo>
 * @Date 2021/7/8 15:12
 * @Version v1.0
 **/
public class BaseUtil {

    /**
     * 获取32位uuid
     *
     * @return
     */
    public static String getPkId() {
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    public static OnlineUser getUser() {
        return RequestHelper.getUser();
    }


    /**
     * 获取用户id
     *
     * @return
     */
    public static String getUserId() {
        try {
            return getUser().getJwtUser().getUsername();
        } catch (Exception e) {
            return "";
        }
    }

    /**
     * 获取用户名
     *
     * @return
     */
    public static String getUserName() {
        try {
            return getUser().getJwtUser().getNickName();
        } catch (Exception e) {
            return "";
        }
    }

    /**
     * 获取IP
     *
     * @return
     */
    public static String getIp() {
        InetAddress addr = null;
        try {
            addr = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {

        }
        if (null != addr) {
            return addr.getHostAddress();
        } else {
            return null;
        }
    }

}
